﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using BenevolentSunData;

namespace BenevolentSun
{
    public class InstructionsControl
    {

        TextField instructionsText;
        public TextField InstructionsText
        {
            get { return instructionsText; }
        }

        Tween tweenInstructionsAlpha;


        public InstructionsControl(ContentManager content)
        {
            SpriteFont instructionsFont = content.Load<SpriteFont>("Fonts/Instructions");
            instructionsText = new TextField("", instructionsFont);
            instructionsText.AlignH = AlignH.Center;
            instructionsText.AlignV = AlignV.Top;
            instructionsText.Position = new Vector2(640, 670);
            instructionsText.Color.A = 0;
        }

        public void Update(GameTime gameTime)
        {
            if (tweenInstructionsAlpha != null)
            {
                tweenInstructionsAlpha.Update(gameTime);
                instructionsText.Color.A = (byte)tweenInstructionsAlpha.Value;
                if (tweenInstructionsAlpha.IsFinished)
                {
                    tweenInstructionsAlpha = null;
                    if (instructionsText.Color.A == 255)
                    {
                        FadeCycleInstructions();
                    }
                }
            }
        }

        public void HideInstructions()
        {
            instructionsText.Color.A = 0;
            tweenInstructionsAlpha = null;
        }

        public void ShowInstructions()
        {
            instructionsText.Color.A = 255;
            tweenInstructionsAlpha = null;
        }

        public void SetInstructions(String text)
        {
            instructionsText.Text = text;
        }

        public void FadeInInstructions()
        {
            tweenInstructionsAlpha = new Tween(instructionsText.Color.A, 255, 0.25, Tween.LoopType.None);
        }

        public void FadeOutInstructions()
        {
            tweenInstructionsAlpha = new Tween(instructionsText.Color.A, 0, 0.25, Tween.LoopType.None);
        }

        public void FadeCycleInstructions()
        {
            tweenInstructionsAlpha = new Tween(255, 0.8f * 255, 0.5, Tween.LoopType.Oscillate);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            instructionsText.Draw(spriteBatch);
        }

    }
}
